# -*- coding: utf-8 -*-
# __author__ = 'xxx'
# env
# function: test send syn
'''
pip install impacket -i https://pypi.tuna.tsinghua.edu.cn/simple
'''

import socket
import impacket.ImpactPacket
import warnings




def sendsynt():
   warnings.filterwarnings("ignore") 

   #sendsocket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
   sendsocket = socket.socket(socket.AF_INET, socket.SOCK_RAW, 'TCP')
   #sendsocket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)



   ip = impacket.ImpactPacket.IP()
   tcp = impacket.ImpactPacket.TCP()
   
   ip.set_ip_src("172.27.1.120")#你的ip
   ip.set_ip_dst("172.27.1.119")#目标ip
   ip.set_ip_ttl(255)#ttl
   
   tcp.set_th_flags(0b00000010)#将syn标志位设为1
   tcp.set_th_sport(2228)#源端口
   tcp.set_th_dport(80)#目标端口
   tcp.set_th_ack(0)
   tcp.set_th_seq(22903)
   tcp.set_th_win(20000)#设置Window Size

   ip.contains(tcp)
   ip.calculate_checksum()

   
   sendsocket.sendto(ip.get_packet(),("172.27.1.119",80))
   #两个参数分别为要发送的数据，类型为bytes与包含目标ip与端口的元祖


sendsynt()


